package com.siwei.mes.tgl.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.siwei.mes.entity.tgl.TglContract;
import com.siwei.mes.mapper.ContractMapper;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * tgl合同
 *
 * @Description: tgl合同
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2024/1/13 11:23
 */
@Service
public class SyncTglContractService {
    private static final Logger log = LoggerFactory.getLogger("tgl");
    @Resource
    private ContractMapper contractMapper;

    public void operateTglContract(TglContract entity) {
        log.info("TGL新增或修改合同,入参：{}", JSON.toJSONString(entity));
        /**unicode转为中文 根据Id判断是否存在*/
        entity.setExtraInfo(StringEscapeUtils.unescapeJava(entity.getExtraInfo()));
        TglContract localInfo = contractMapper.selectByCid(entity.getCid());
        if (localInfo != null) {
            if (ObjectUtil.isEmpty(localInfo.getSynctime()) || entity.getSynctime() > localInfo.getSynctime()) {
                entity.setId(localInfo.getId());
                contractMapper.updateByPrimaryKeySelective(entity);
            }
        } else {
            contractMapper.insertSelective(entity);
        }
    }
}
